package com.yxq.mdt.app.modules.personal.adapter;

import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.yxq.mdt.app.R;
import com.yxq.mdt.app.glide.GlideHelper;
import com.yxq.mdt.app.modules.personal.bean.GroupBean;

import java.util.List;

/**
 * @author L
 * @time 2019-11-19
 * @describe 我的-我的圈子列表
 */
public class MineCircleListAdapter extends BaseQuickAdapter<GroupBean.ListBean, BaseViewHolder> {

    public MineCircleListAdapter(int layoutResId, @Nullable List<GroupBean.ListBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, GroupBean.ListBean item) {
        helper.setText(R.id.item_group_tv_group_name, item.getGroupname());
        helper.setText(R.id.item_group_tv_manager_name, "圈主：" + (item.getOwnerVo().getUserName() == null ? "" : item.getOwnerVo().getUserName()));
        helper.setText(R.id.item_group_tv_group_info, "圈子简介：" + item.getDescription());
        helper.setText(R.id.item_group_tv_group_number, String.format("%d   成员      %d   动态", item.getMenberNum(), item.getDynamicNum()));
        GlideHelper.setLoadRoundImage(mContext, item.getLogo(), R.color.gray, helper.getView(R.id.circle_iv_logo));
        if (item.getMenberList() != null && item.getMenberList().size() > 0) {
            int size = item.getMenberList().size();
            if (size == 1) {
                GlideHelper.setLoadRoundImage(mContext, item.getMenberList().get(0).getHeadimg(), R.color.gray, helper.getView(R.id.item_group_iv_member_head1));
            } else if (size == 2) {
                GlideHelper.setLoadRoundImage(mContext, item.getMenberList().get(0).getHeadimg(), R.color.gray, helper.getView(R.id.item_group_iv_member_head1));
                GlideHelper.setLoadRoundImage(mContext, item.getMenberList().get(1).getHeadimg(), R.color.gray, helper.getView(R.id.item_group_iv_member_head2));
            } else if (size >= 3) {
                GlideHelper.setLoadRoundImage(mContext, item.getMenberList().get(0).getHeadimg(), R.color.gray, helper.getView(R.id.item_group_iv_member_head1));
                GlideHelper.setLoadRoundImage(mContext, item.getMenberList().get(1).getHeadimg(), R.color.gray, helper.getView(R.id.item_group_iv_member_head2));
                GlideHelper.setLoadRoundImage(mContext, item.getMenberList().get(2).getHeadimg(), R.color.gray, helper.getView(R.id.item_group_iv_member_head3));
            }
        } else {
            helper.setGone(R.id.item_group_iv_member_head1, false);
            helper.setGone(R.id.item_group_iv_member_head2, false);
            helper.setGone(R.id.item_group_iv_member_head3, false);
        }
        helper.addOnClickListener(R.id.item_group_tv_group_join);
    }

}
